package cn.wolfcode.luowowo2.articleserver.service.imp;

import cn.wolfcode.luowowo2.article.domain.Region;
import cn.wolfcode.luowowo2.article.mapper.RegionMapper;
import cn.wolfcode.luowowo2.article.service.IRegionService;
import cn.wolfcode.luowowo2.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Albert on 2019/7/8.
 */
@Service
public class RegionServiceImpl implements IRegionService{
    @Autowired
    private RegionMapper mapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Region> list = mapper.selectForList();
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(Region region) {
        if (region.getId() == null) {
            mapper.insert(region);
        } else {
            mapper.updateByPrimaryKey(region);
        }
    }

    @Override
    public void changeHotValue(Boolean hot, Long id) {
        mapper.updateHotValue(hot,id);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Region get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Region> getHotRegion() {
        return mapper.selectHotRegion();
    }
}
